package com.cn.pack;

import com.netflix.zuul.FilterFileManager;
import com.netflix.zuul.FilterLoader;
import com.netflix.zuul.groovy.GroovyCompiler;
import com.netflix.zuul.groovy.GroovyFileFilter;
import com.netflix.zuul.monitoring.MonitoringHelper;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.stereotype.Component;

@SpringBootApplication
@EnableZuulProxy
@EnableDiscoveryClient
public class GroovyFilterApp {

    public static void main(String[] args) {
        SpringApplication.run(GroovyFilterApp.class, args);
    }

    @Component
    public static class GroovyRunner implements CommandLineRunner {
        @Override
        public void run(String... args) throws Exception {
            MonitoringHelper.initMocks();
            FilterLoader.getInstance().setCompiler(new GroovyCompiler());
            FilterFileManager.setFilenameFilter(new GroovyFileFilter());
            //将编写的GroovyFilter.java文件复制到该目录下，并重新命名为GroovyFilter.groovy
            // FilterFileManager会开启一个线程，定时扫描指定目录下的*.groovy文件
            FilterFileManager.init(5, "D:/myProjects/file");
        }
    }
}
